# encoding=utf8

from flask import Flask, render_template
from app.config import config
from app.extensions import init_extensions
from app.view import init_blueprint


def init_error_handler(app):
    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('error/404.html', e=e)


def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config.get(config_name) or 'default')
    config.get(config_name).init_app(app)

    init_extensions(app)

    init_blueprint(app)

    init_error_handler(app)

    return app
